<template>
  <div class="app-container">
    <el-form ref="ref" :model="model" :rules="rules" class="dialog-body" label-width="100px">
      <el-form-item label="名称" prop="name">
        <el-input v-model="model.name" placeholder="请输入名称" clearable/>
      </el-form-item>
      <el-form-item label="详细" prop="info">
        <el-input v-model="model.info" type="textarea" maxlength="40" placeholder="" show-word-limit/>
      </el-form-item>
      <el-form-item label="排序" prop="sort">
        <el-input-number v-model="model.sorting" :min="1" :max="99999" step-strictly/>
      </el-form-item>

      <el-form-item label="">
        <el-button type="primary" @click="submit">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import screenHeight from '@/utils/screen-height'
import {info, save} from '@/api/admin/test'

export default {
  name: 'AdminUser',
  components: {},
  data() {
    return {
      height: 680,
      loading: false,
      model: {
        id: '',
        created_at: '',
        updated_at: '',
        name: '',
        remark: '',
        status: '',
        sorting: 100,
      },
      ruleDialog: false,
      rules: {
        name: [{required: true, message: '请输入名称', trigger: 'blur'}]
      }
    }
  },
  created() {
    this.height = screenHeight()
    const id = this.$route.params && this.$route.params.id
    info({
      id: id
    }).then(response => {
      this.model = response.data

      // set tagsview title
      this.setTagsViewTitle()
      // set page title
      this.setPageTitle()
    }).catch(err => {
      console.log(err)
    })
  },
  methods: {
    // 提交
    submit() {
      this.$notify({
        title: 'Success',
        dangerouslyUseHTMLString: true,
        message: `
            <div>名称: ${this.model.name}</div>
            <div>详细: ${this.model.info}</div>
            <div>排序: ${this.model.sorting}</div>
          `,
        type: 'success'
      })
    },

    setTagsViewTitle() {
      const title = '编辑数据'
      const route = Object.assign({}, this.tempRoute, {title: `${title}-${this.postForm.id}`})
      this.$store.dispatch('tagsView/updateVisitedView', route)
    },
    setPageTitle() {
      const title = '编辑数据'
      document.title = `${title} - ${this.postForm.id}`
    },
  }
}
</script>
